package com.szs.service.impl;

import com.szs.mapper.ClazzMapper;
import com.szs.mapper.EmpMapper;
import com.szs.pojo.ClazzOption;
import com.szs.pojo.JobOption;
import com.szs.service.ReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;

@Service
public class ReportServiceImpl implements ReportService {
    /*
     * 统计员工职位人数
     * */
    @Autowired
    private EmpMapper empMapper;
    @Autowired
    private ClazzMapper clazzMapper;

    @Override
    public JobOption getEmpJobData() {
        //1 调用Mapper接口，获取统计数据
        List<Map<String, Object>> list = empMapper.countEmpJobData();// map集合 ：pos=‘教研主管’  num=1

        //2 组装结果，并返回
        List<Object> jobList = list.stream().map(dateMap ->dateMap.get("pos")).toList();
        List<Object> dataList = list.stream().map(dateMap ->dateMap.get("num")).toList();
        return new JobOption(jobList, dataList);
    }

    @Override
    public List<Map<String, Object>> getEmpGenderData() {
        return empMapper.countEmpGenderData();
    }
/*
* 统计班级信息
* */
    @Override
    public ClazzOption getClassData() {
       //1. 调用Mapper接口，获得统计数据
       List<Map<String,Object>> list = clazzMapper.countClazzData();

       //2组装结果并返回
        List<Object> clazzList = list.stream().map(dataMap -> dataMap.get("clazzName")).toList();
        List<Object> dataList = list.stream().map(dataMap ->dataMap.get("studentCount")).toList();
        return new ClazzOption(clazzList, dataList);
    }
/*
* 统计学员学历信息
* */
    @Override
    public List<Map<String, Object>> getClassDegreeData() {
        return clazzMapper.getClassDegreeData();
    }
}
